import unittest,time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

class Baidu1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.get('https://www.baidu.com/index.htm')

    def tearDown(self):
        time.sleep(5)

        self.driver.quit()
    def test_baidu1(self):
        # self.assertEqual(True, False)  # add assertion here

        time.sleep(2)
        # 输入框输入web自动化测试
        search=self.driver.find_element(By.ID,'kw')
        search.send_keys('web自动化测试')
        search.send_keys(Keys.ENTER)
        time.sleep(2)
        # 点击右键
        ActionChains(self.driver).context_click(search).perform()
        time.sleep(2)
        # 双击输入框
        ActionChains(self.driver).double_click(search).perform()
        time.sleep(2)
        # Ctrl+c复制
        search.send_keys(Keys.CONTROL,'c')
        time.sleep(10)
        # 鼠标悬停
        xt=self.driver.find_element(By.CLASS_NAME,'pf')
        ActionChains(self.driver).move_to_element(xt).perform()
        time.sleep(2)
        # 点击高级搜索
        self.driver.find_element(By.LINK_TEXT,'高级搜索').click()
        time.sleep(2)
        # 在输入框中Ctrl+v
        q1=self.driver.find_element(By.NAME,'q1')
        q1.send_keys(Keys.CONTROL,'v')
        time.sleep(2)

        ActionChains(self.driver).double_click(q1).perform()
        time.sleep(2)

        q1.send_keys(Keys.CONTROL,'x')
        time.sleep(2)

        q4 = self.driver.find_element(By.NAME, 'q4')
        q4.send_keys(Keys.CONTROL, 'v')
        time.sleep(2)

    def test_baidu2(self):
        # self.assertEqual(True, False)  # add assertion here

        time.sleep(2)
        # 输入框输入web自动化测试
        search=self.driver.find_element(By.ID,'kw')
        search.send_keys('web自动化测试')
        search.send_keys(Keys.ENTER)
        time.sleep(2)
        # 点击右键
        # ActionChains(self.driver).context_click(search).perform()
        # time.sleep(2)
        # 三击输入框
        ActionChains(self.driver).double_click(search).click(search).perform()
        time.sleep(2)
        # Ctrl+c复制
        search.send_keys(Keys.CONTROL,'c')
        time.sleep(10)
        # 鼠标悬停
        xt=self.driver.find_element(By.CLASS_NAME,'pf')
        ActionChains(self.driver).move_to_element(xt).perform()
        time.sleep(2)
        # 点击高级搜索
        self.driver.find_element(By.LINK_TEXT,'高级搜索').click()
        time.sleep(2)
        # 在输入框中Ctrl+v
        q1=self.driver.find_element(By.NAME,'q1')
        q1.send_keys(Keys.CONTROL,'v')
        time.sleep(2)

        ActionChains(self.driver).double_click(q1).perform()
        time.sleep(2)

        q1.send_keys(Keys.CONTROL,'x')
        time.sleep(2)

        q4 = self.driver.find_element(By.NAME, 'q4')
        q4.send_keys(Keys.CONTROL, 'v')
        time.sleep(2)

        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[5]/div/div/div/div[2]/div/form/ul/li[2]/span[2]/div/div[1]/span').click()
        time.sleep(2)

        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[5]/div/div/div/div[2]/div/form/ul/li[2]/span[2]/div/div[2]/div[2]/p[4]').click()
        time.sleep(2)

        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[5]/div/div/div/div[2]/div/form/ul/li[3]/span[2]/div/div[1]').click()
        time.sleep(2)

        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[5]/div/div/div/div[2]/div/form/ul/li[3]/span[2]/div/div[2]/div[2]/p[5]').click()
        time.sleep(2)

        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[5]/div/div/div/div[2]/div/form/ul/li[6]/div/input[2]').click()

if __name__ == '__main__':
    unittest.main()
